package org.classdef.analyzer;

import org.classdef.analyzer.info.ClassDef;
import org.classdef.analyzer.info.accesstype.ClassAccessType;
import org.classdef.analyzer.info.attribute.AttributePool;
import org.classdef.analyzer.info.constant.ConstantPool;
import org.classdef.analyzer.info.field.FieldInfo;
import org.classdef.analyzer.info.field.FieldPool;
import org.classdef.analyzer.info.method.MethodInfo;
import org.classdef.analyzer.info.method.MethodPool;

public class ClassLog {

	private ClassDef info;
	
	public ClassLog(ClassDef info){
		this.info = info;
	}
	
	public void log(){
		ConstantPool constantPool = info.getConstantPool();
		FieldPool fieldPool = info.getFieldPool();
		MethodPool methodPool = info.getMethodPool();
		AttributePool attributePool = info.getAttributePool();
		
		System.out.println("版本: " + info.getMajor() + "." + info.getMinor());
		
		short accessFlags = (short)(info.getAccessFlags() & (~0x0020));
		
		System.out.println("修饰: " + ClassAccessType.getType(accessFlags));
		System.out.println("类名: " + constantPool.get(info.getThisClass()).getValue().toString().replaceAll("/", "."));
		System.out.println("父类: " + constantPool.get(info.getSuperClass()).getValue().toString().replaceAll("/", "."));
		System.out.println("接口数: " + info.getInterfacesCount());
		System.out.println("接口 : ");
		for (short interfaceIndex : info.getInterfacesIndeies()) {
			System.out.println("     " + constantPool.get(interfaceIndex).getValue().toString().replaceAll("/", "."));
		}
		System.out.println("成员变量数: " + info.getFieldCount());
		System.out.println("成员变量: " + info.getFieldCount());
		for (FieldInfo info : fieldPool.getInfos()) {
			System.out.println("     修饰: " + ClassAccessType.getType(info.getAccessFlags()));
			System.out.println("     变量名: " + constantPool.get(info.getNameIndex()).getValue());
			System.out.println("     描述: " + constantPool.get(info.getDescriptorIndex()).getValue());
			System.out.println("     attribute数: " + info.getAttributesCount());
			System.out.println("     attribute: " + info.getAttributePool());
			
			System.out.println("\r\n");
		}
		
		System.out.println("方法数: " + info.getMethodCount());
		System.out.println("方法: ");
		for (MethodInfo info : methodPool.getInfos()) {
			System.out.println("     修饰: " + ClassAccessType.getType(info.getAccessFlags()));
			System.out.println("     方法名: " + constantPool.get(info.getNameIndex()).getValue());
			System.out.println("     描述: " + constantPool.get(info.getDescriptorIndex()).getValue());
			System.out.println("     attribute数: " + info.getAttributesCount());
			System.out.println("     attribute: " + info.getAttributePool());
			
			System.out.println("\r\n");
		}
//		System.out.println("attribute数: " + info.getAttributeCount());
//		System.out.println("attribute: ");
//		for (AttributeInfo info : attributePool.getInfos()) {
//			System.out.println("     attribute名: " + constantPool.get(info.getAttributeNameIndex()).getValue());
//			System.out.println("     长度: " + info.getAttributeLength());
//			
//			System.out.println("\r\n");
//		}
//		System.out.println("============================================");
//		System.out.println(info);
	}
}
